package com.jp.api.controller;

import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 向量数据库
 */
@RestController
@RequestMapping("/victor")
public class VectorController {

    @Autowired
    private VectorStore vectorStore;

    @GetMapping("/add")
    public Object add(){
        List<Document> list = List.of(new Document("你好，我是小月，春天来了，万物复苏，我们一起出去玩吧！", Map.of("meta1","meta1")));
        vectorStore.add(list);
        return 2;
    }

    @GetMapping("/query")
    public Object query(String msg){
        List<Document> results = this.vectorStore.similaritySearch(SearchRequest.builder().query(msg).topK(1).build());
        return results;
    }
}
